package com.jskj.commons;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 输出字符串
	 * @param str----字符串
	 * @return 无
	 */
	protected void out(String str) {
		/*HttpServletRequest req=ServletActionContext.getRequest();*/
		HttpServletResponse resp=ServletActionContext.getResponse();
		resp.setCharacterEncoding("UTF-8");
		resp.setContentType("text/html;charset=utf-8");
		if (str == null) {
			str="";
		}
		try {
			PrintWriter pw=resp.getWriter();
			pw.print(str);
			pw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	/**
	 * 返回成功字符串
	 * @return success
	 */
	protected String outSuccess() {
		return "success";
	}
	/**
	 * 跳转到指定的地址
	 * @param url
	 */
	protected void outUrl(String url) {
		HttpServletRequest req=ServletActionContext.getRequest();
		HttpServletResponse resp=ServletActionContext.getResponse();
		if(url!=null){
			try {
				req.getRequestDispatcher(url).forward(req, resp);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
